import path from 'path';
import PluginReact from '@vitejs/plugin-react';
import { defineMvConfig } from 'vite-electron-simple';

export default () =>
    defineMvConfig({
        privateConfig: {
            needElectron: true,
            tsMainConfigPath: path.resolve(__dirname, './tsconfig.main.json'),
            move: [
                {
                    from: 'electron/static',
                    to: 'dist_electron/static'
                }
            ]
        },
        viteConfig: {
            base: './',
            plugins: [PluginReact()],
            resolve: {
                alias: {
                    '@': path.resolve(__dirname, './src')
                }
            },
            css: {
                preprocessorOptions: {
                    less: {
                        additionalData: `@import '@/style/variable.less';`
                    }
                }
            }
        },
        electronBuilder: {
            appId: 'com.join.care.print',
            productName: 'Join-Care Print',
            directories: {
                output: 'bundle'
            },
            extraResources: {
                from: 'electron/static/application',
                to: 'static/application'
            },
            files: [
                '**/*',
                '!**/*.ts',
                '!tsconfig.json',
                '!yarn.lock',
                '!package-lock.json'
            ],
            win: {
                sign: null,
                target: 'nsis',
                icon: 'dist_electron/static/logo.png'
            },
            nsis: {
                oneClick: false,
                allowToChangeInstallationDirectory: true,
                createDesktopShortcut: true,
                deleteAppDataOnUninstall: true,
                include: './install.nsh'
            },
            protocols: [
                {
                    name: 'react-electron-template',
                    schemes: ['react-electron-template']
                }
            ]
        }
    });
